<?php
namespace app\mobile\model;

class MemberCollect extends BaseModel
{
    //查找会员收藏商品或店铺数量
    public function echo_collect($member_id)
    {
        $data['goods'] = self::with('shopGoods')->where(['member_id'=>$member_id,'type_id'=>1])->count('id');
        $data['shop'] = self::with('shop')->where(['member_id'=>$member_id,'type_id'=>2])->count('id');
        return $data;
    }
    //检测会员是否收藏过此店铺
    public function is_collected($member_id,$shop_id)
    {
        $res = self::where(['member_id'=>$member_id,'type_id'=>2,'collect_id'=>$shop_id])->find();
        return $res?$res['id']:0;
    }
    /*
     * 收藏表和店铺多对一
     */
    public function shop()
    {
        return $this->belongsTo('Shop','collect_id','member_id');
    }
    /*
     * 收藏表和商品多对一
     */
    public function shopGoods()
    {
        return $this->belongsTo('ShopGoods','collect_id','id');
        // ->where(['status'=>1,'state'=>1])
    }
}